#!/bin/sh

# build_fat.sh
#
# Created by Robert Carlsen on 15.07.2009.
# build an arm / i686 lib of standard linux project
#
# adopted from: http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html
#
# copied from: http://robertcarlsen.net/2009/07/15/cross-compiling-for-iphone-dev-884
#
# initially configured for libical

# Restore default environment variables
unset CPPFLAGS CFLAGS CPP LDFLAGS CXXFLAGS

find . -name \*.a -exec rm {} \;

# set the prefix
ARCH=i386
PREFIX=${HOME}/Library/libical
OUTPUTDIR=../libical-build

export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.1.2.sdk
export CFLAGS="-O -g -arch $ARCH -I$SDKROOT/usr/include"

if [ ! -d $SDKROOT ]
then
	echo "SDK Root not found! - $SDKROOT"
	exit
fi

echo "SDKROOT = $SDKROOT"
echo "CPPFLAGS = $CPPFLAGS"
echo "CFLAGS = $CFLAGS"
echo "LDFLAGS = $LDFLAGS"

# TODO: add custom flags as necessary for package
./configure --prefix=$PREFIX --disable-dependency-tracking 

make -j4

echo "#############################################################"
echo "#############################################################"
echo "#############################################################"

mkdir -p $OUTPUTDIR
mkdir -p $OUTPUTDIR/$ARCH

cp `find . -name \*.a` $OUTPUTDIR/$ARCH/

ls -lh $OUTPUTDIR/$ARCH/*.a
lipo -info $OUTPUTDIR/$ARCH/*.a

echo $ARCH DONE

